package com.jn.gsondemo.views;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.gsondemo.Adapter.HotSearchAdapter;
import com.jn.gsondemo.R;
import com.jn.gsondemo.entity.HotSearchItem;

import java.util.ArrayList;
import java.util.List;

public class HotSearchFragment extends Fragment {

    private RecyclerView recyclerView;
    private HotSearchAdapter adapter;
    private List<HotSearchItem> hotSearchItems = new ArrayList<>();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hot_search, container, false);

        recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 加载数据
        loadHotSearchData();

        return view;
    }

    private void loadHotSearchData() {
        // 假设这里是从服务器获取数据，简化示例中直接添加几个测试数据
        for (int i = 0; i < 10; i++) {
            HotSearchItem item = new HotSearchItem();
            item.setTitle("热点" + i);
            item.setHotValue("热度" + i * 10000);
            item.setLink("http://example.com");
            hotSearchItems.add(item);
        }

        adapter = new HotSearchAdapter(getContext(), hotSearchItems);
        recyclerView.setAdapter(adapter);
    }
}